type TargetContext = '_self' | '_parent' | '_blank' | '_top';

/**
 * 打开新窗口
 * @function
 * @memberof Utils
 */
export const openWindow = (url: string, opts?: { target?: TargetContext;[key: string]: any }) => {
    const { target = '_blank', ...others } = opts || {};
    window.open(
        url,
        target,
        Object.entries(others)
            .reduce((preValue: string[], curValue) => {
                const [key, value] = curValue;
                return [...preValue, `${key}=${value}`];
            }, [])
            .join(',')
    );
};

/**
 * 获取价格整数部分
 * @function
 * @memberof Utils
 */
export const getIntegerPart = (price: string | number) => {
    if (!price || price === '--') return '--';
    return String(price).split('.')[0];
}

/**
 * 获取价格小数部分
 * @function
 * @memberof Utils
 */
export const getDecimalPart = (price: string | number) => {
    if (!price || price === '--') return '00';
    const parts = String(price).split('.');
    return parts[1] ? parts[1] : '00';
}